package cases

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/cases"
	casesReq "github.com/flipped-aurora/gin-vue-admin/server/model/cases/request"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type CasCasesApi struct{}

// CreateCasCases 创建casCases表
// @Tags CasCases
// @Summary 创建casCases表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body cases.CasCases true "创建casCases表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /casCases/createCasCases [post]
func (casCasesApi *CasCasesApi) CreateCasCases(c *gin.Context) {
	var casCases cases.CasCases
	err := c.ShouldBindJSON(&casCases)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = casCasesService.CreateCasCases(&casCases)
	if err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("创建成功", c)
}

// DeleteCasCases 删除casCases表
// @Tags CasCases
// @Summary 删除casCases表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body cases.CasCases true "删除casCases表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /casCases/deleteCasCases [delete]
func (casCasesApi *CasCasesApi) DeleteCasCases(c *gin.Context) {
	ID := c.Query("ID")
	err := casCasesService.DeleteCasCases(ID)
	if err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteCasCasesByIds 批量删除casCases表
// @Tags CasCases
// @Summary 批量删除casCases表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /casCases/deleteCasCasesByIds [delete]
func (casCasesApi *CasCasesApi) DeleteCasCasesByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
	err := casCasesService.DeleteCasCasesByIds(IDs)
	if err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateCasCases 更新casCases表
// @Tags CasCases
// @Summary 更新casCases表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body cases.CasCases true "更新casCases表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /casCases/updateCasCases [put]
func (casCasesApi *CasCasesApi) UpdateCasCases(c *gin.Context) {
	var casCases cases.CasCases
	err := c.ShouldBindJSON(&casCases)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = casCasesService.UpdateCasCases(casCases)
	if err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindCasCases 用id查询casCases表
// @Tags CasCases
// @Summary 用id查询casCases表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query cases.CasCases true "用id查询casCases表"
// @Success 200 {object} response.Response{data=cases.CasCases,msg=string} "查询成功"
// @Router /casCases/findCasCases [get]
func (casCasesApi *CasCasesApi) FindCasCases(c *gin.Context) {
	ID := c.Query("ID")
	recasCases, err := casCasesService.GetCasCases(ID)
	if err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:"+err.Error(), c)
		return
	}
	response.OkWithData(recasCases, c)
}

// GetCasCasesList 分页获取casCases表列表
// @Tags CasCases
// @Summary 分页获取casCases表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query casesReq.CasCasesSearch true "分页获取casCases表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /casCases/getCasCasesList [get]
func (casCasesApi *CasCasesApi) GetCasCasesList(c *gin.Context) {
	var pageInfo casesReq.CasCasesSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, amount, err := casCasesService.GetCasCasesInfoList(pageInfo)
	if err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败:"+err.Error(), c)
		return
	}
	response.OkWithDetailed(response.PageResult{
		List:     list,
		Total:    total,
		Amount:   amount,
		Page:     pageInfo.Page,
		PageSize: pageInfo.PageSize,
	}, "获取成功", c)
}

// GetCasCasesDataSource 获取CasCases的数据源
// @Tags CasCases
// @Summary 获取CasCases的数据源
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "查询成功"
// @Router /casCases/getCasCasesDataSource [get]
func (casCasesApi *CasCasesApi) GetCasCasesDataSource(c *gin.Context) {
	// 此接口为获取数据源定义的数据
	dataSource, err := casCasesService.GetCasCasesDataSource()
	if err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:"+err.Error(), c)
		return
	}
	response.OkWithData(dataSource, c)
}

// GetCasCasesPublic 不需要鉴权的casCases表接口
// @Tags CasCases
// @Summary 不需要鉴权的casCases表接口
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /casCases/getCasCasesPublic [get]
func (casCasesApi *CasCasesApi) GetCasCasesPublic(c *gin.Context) {
	// 此接口不需要鉴权
	// 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
	casCasesService.GetCasCasesPublic()
	response.OkWithDetailed(gin.H{
		"info": "不需要鉴权的casCases表接口信息",
	}, "获取成功", c)
}
